package com.example.report;

import com.example.entity.SpotObjectCensus;
import com.example.service.SpotObjectPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class CheckItemReport {

    @Autowired
    public SpotObjectPlanService spotObjectPlanService;


    // 获取检查内容
    public List<SpotObjectCensus> title(String dsName,String datasetName, Map<String, Object> parameters) {

        // 计划Id
        String planId = null;
        Object id = parameters.get("planId");
        if(id !=null){
            planId = String.valueOf(id);
        }
        // 设备Id
        String elevatorId="";
        Object elevatorNum = parameters.get("elevatorId");
        if(elevatorNum !=null){
            elevatorId = String.valueOf(elevatorNum);
        }

        // 被检查人
        String implementObject = "";
        Object implementObjectMan = parameters.get("implementObject");
        if(implementObjectMan !=null){
            implementObject = String.valueOf(implementObjectMan);
        }

        // 检查人
        String checkMan = "";
        Object checkMans = parameters.get("checkMan");
        if(checkMans !=null){
            checkMan = String.valueOf(checkMans);
        }

        // 查询数据
        SpotObjectCensus objectCensus = new SpotObjectCensus();
        objectCensus.setPlanId(Long.valueOf(planId));
        objectCensus.setElevatorId(elevatorId);
        objectCensus.setImplementObject(implementObject);
        objectCensus.setCheckMan(checkMan);
        List<SpotObjectCensus> list = spotObjectPlanService.exportExcelClown(objectCensus);
        if (list != null && list.size() > 0) {
            for(int i=0;i<list.size();i++){
                list.get(i).setId(Long.valueOf(i+1));
            }
        }

        return list;
    }

    // 获取检查时间 检查人 检查评价 检查总结和意见
    public List<Map> optionAndCheck(String dsName,String datasetName, Map<String, Object> parameters) {

        List<Map> restlt = new ArrayList<>();

        Map<String,String> map = new HashMap<>();

        // 计划Id
        String planId = null;
        Object id = parameters.get("planId");
        if(id !=null){
            planId = String.valueOf(id);
        }
        // 设备Id
        String elevatorId="";
        Object elevatorNum = parameters.get("elevatorId");
        if(elevatorNum !=null){
            elevatorId = String.valueOf(elevatorNum);
        }

        // 被检查人
        String implementObject = "";
        Object implementObjectMan = parameters.get("implementObject");
        if(implementObjectMan !=null){
            implementObject = String.valueOf(implementObjectMan);
        }

        // 检查人
        String checkMan = "";
        Object checkMans = parameters.get("checkMan");
        if(checkMans !=null){
            checkMan = String.valueOf(checkMans);
        }

        // 查询数据
        SpotObjectCensus objectCensus = new SpotObjectCensus();
        objectCensus.setPlanId(Long.valueOf(planId));
        objectCensus.setElevatorId(elevatorId);
        objectCensus.setImplementObject(implementObject);
        objectCensus.setCheckMan(checkMan);
        List<SpotObjectCensus> list = spotObjectPlanService.exportExcelClown(objectCensus);
        if (list != null && list.size() > 0) {
            SpotObjectCensus spotObjectCensus = list.get(0);

            map.put("createDate"," 检查时间："+spotObjectCensus.getCreateDate());

            if("0".equals(spotObjectCensus.getResultEvaluate())){
                map.put("resultEvaluate"," 检查评论： √优 □良 □差");
            }else if("1".equals(spotObjectCensus.getResultEvaluate())){
                map.put("resultEvaluate"," 检查评论： □优 √良 □差");
            }else{
                map.put("resultEvaluate"," 检查评论： □优 □良 √差");
            }
            map.put("option"," 检查意见："+spotObjectCensus.getOpinion());
        }

        map.put("checkMan"," 检查人："+checkMan);

        restlt.add(map);

        return restlt;
    }
}
